;
! function() {
	var layer = layui.layer,
		form = layui.form,
		carousel = layui.carousel;


	console.log('self.location',self.location)
	console.log('top.location',top.location)
	// 登录过期的时候，跳出ifram框架
	if (top.location != self.location) {
		top.location = self.location;
	}

	// 粒子线条背景
	$(document).ready(function(){
		$('.layui-container').particleground({
			dotColor:'#5cbdaa',
			lineColor:'#5cbdaa'
		});
	});
	// 背景图片轮播
	carousel.render({
		elem: '#login_carousel',
		width: '100%',
		height: '100%',
		interval: 3000,
		arrow: 'none',
		anim: 'fade',
		indicator: 'none'
	});

	/*// 验证码值存储变量
	var vailCode;
	// 执行获取验证码
	refCode();

	// 点击刷新验证码
	$("#refCode_login_img").on("click", function() {
		refCode();
	});

	// 获取验证码
	function refCode() {
		$.ajax({
			url: "user/imageVailCode.do",
			type: "post",
			success: function(result) {
				vailCode = result.data.rand;
				$("#refCode_login_img").prop("src", "data:image/jpg;base64," + result.data.image);
				$("#code").val("");
			}
		});
	}*/

	// 自定义验证规则
	form.verify({
		username: function(value) {
			var regPhone = /^[A-Za-z0-9]+$/;
			if(!regPhone.test(value.trim())) {
				return "账号必须是字母或数字";
			}
		}
	});

	//监听提交
	form.on("submit(login)", function(data) {
		data = data.field;
		console.log('data',data)
		if (data.username == '') {
			layer.msg('用户名不能为空');
			return false;
		}
		if (data.password == '') {
			layer.msg('密码不能为空');
			return false;
		}
		if (data.captcha == '') {
			layer.msg('验证码不能为空');
			return false;
		}
		$.ajax({
			url: ctx + "login",
			type: "POST",
			data: data,
			success: function(result) {
				console.log("登录返回 login ：", result)
				if(result.code == 0) {
					location = ctx + "index?group_code="+$('#group_code').val();
				} else {
					$("#password").val("");
					layer.alert(result.msg, {
						title: '提交结果'
					});
				}
			}
		});

		return false;
	});

	$("input").keydown(function(event){
		if (event.keyCode == 13) {
			document.getElementById("loginBtn").click();
		}
	})
}();
